/*
package com.itheima.web.Filter;

import com.itheima.domain.Manager;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebFilter("/jsp")
public class LoginFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        //获得session中的manager信息
        //ServletRequest没有getSession方法，需要进行强转
        HttpServletRequest request =(HttpServletRequest)req;
        Manager manager = (Manager) request.getSession().getAttribute("manager");
        HttpServletResponse response =(HttpServletResponse)resp;

        //判断manager是否为null
        if (manager==null) {
            //如果为null那么就回显错误信息，然后回到登录界面
//            req.getRequestDispatcher("./login.jsp").forward(req,resp);
            response.sendRedirect(((HttpServletRequest) req).getContextPath()+"/login.jsp");
        }else{

            //如果不为空直接放行
            req.getRequestDispatcher("./list.jsp").forward(req,resp);
            //放行
            chain.doFilter(req, resp);
        }

    }

    public void init(FilterConfig config) throws ServletException {

    }

}
*/
